/*
 * 使用示例:
 * app.use(ip());
 */
'use strict';

exports = module.exports = () => {
  return async(ctx, next) => {
    if (ctx.request.ip === '::1') {
      ctx.request.ip = '127.0.0.1';
    } else {
      ctx.request.ip = ctx.request.ip.replace(/^::ffff:/, '');
    }
    await next();
  };
}